<template>
	<view class="container">
		<view style="margin: 0 auto;">
			
			<!-- 主体表单 -->
			<uni-forms :value="formData" ref="form" :rules="rules" >
				<uni-forms-item label="新密码" name="password">
					<uni-easyinput type="password" v-model="formData.password" focus />
				</uni-forms-item>
				<uni-forms-item label="确认密码" name="repassword">
					<uni-easyinput type="password" v-model="formData.repassword" />
				</uni-forms-item>
				<button type="" @click="submitForm"> 提 交 </button>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	import { repassword} from '@/api/public.js'
	export default {
		
		data() {
			return {
				formData:{
					password:'',
					repassword:''
				},
				rules: {
					// 对字段进行必填验证
					password: {
						rules: [
							{
								minLength: 6,
								maxLength: 15,
								errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符',
							}
						]
					}
				}
			};
		},
		components: {
		},
		onLoad(options) {
			// 初始化页面,执行查看已授权信息
			
		},
		methods: {
			
			submitForm(){
				let _this = this;
				if(typeof(_this.formData.password) == "string" && _this.formData.password === _this.formData.repassword){
					this.$refs.form.submit().then(data => {
						repassword(data).then(res=>{
							if(res.code == 20000){
								uni.showToast({
									icon:'success',
									title: "修改成功",
									duration: 2000
								})
								
							} else {
								uni.showToast({
									icon:'none',
									title: res.data.result,
									duration: 2000
								})
							}
							
						}).catch(err=>{
							uni.showToast({
								icon:'none',
								title: err,
								duration: 2000
							})
						})
					}).catch(err => {
						console.log('表单错误信息：', err);
					})
				}else{
					uni.showToast({
						icon:'error',
						title: "两次输入需一致",
						duration: 1000
					})
				}
			}
		}
	}
</script>

<style>
	
</style>
